package com.dubito.dose.data

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.dubito.dose.data.entity.MedicationEntity
import java.util.Date
import kotlinx.coroutines.flow.Flow

/**
 * author: LiLiang
 * createTime: 2022/9/5-13:21
 * remark:
 **/

@Dao
interface MedicationDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insertMedication(medicationEntity: MedicationEntity)

    @Delete
    suspend fun deleteMedication(medicationEntity: MedicationEntity)

    @Query(
        """
            SELECT * FROM medicationEntity
        """
    )
    fun getAllMedications() : Flow<List<MedicationEntity>>

    @Query(
        """
            SELECT * 
            FROM medicationEntity
            WHERE endDate > :date
        """
    )
    fun getMedicationsForDate(date: Date): Flow<List<MedicationEntity>>
}